"""
Case Type   : 资源池化
Case Name   : 备机上执行缩容
Create At   : 2024.10
Owner       : chen
Description :
    1.备机上执行缩容
    gs_dropnode -U USER -G GROUP -h hostlist
Expect      :
    1.合理报错
"""

import os
import unittest
from testcase.utils.Logger import Logger
from testcase.utils.CommonSH import CommonSH
from testcase.utils.Constant import Constant
from yat.test import Node
from yat.test import macro

class SharedStorage(unittest.TestCase):
    def setUp(self):
        self.log = Logger()
        self.log.info(f'-----{os.path.basename(__file__)} start-----')
        self.pri_comsh = CommonSH('PrimaryDbUser')
        self.constant = Constant()
        self.sta1_node = Node('Standby1DbUser')
        self.db_host = Node('Standby2DbUser').db_host
        self.s_user = self.sta1_node.ssh_user
        
    def test_shared_storage(self):
        text = f'''-----step1: 备机上执行缩容 expect: 合理报错-----'''
        self.log.info(text)
        cmd = f'''source {macro.DB_ENV_PATH};
        expect <<EOF
        set timeout 600
        spawn gs_dropnode -U {self.s_user} -G {self.s_user} \
            -h {self.db_host}
        expect "*drop the target node (yes/no)?*"
        send "yes\\n"
        expect eof\n''' + '''EOF'''
        self.log.info(cmd)
        res = self.sta1_node.sh(cmd).result()
        self.log.info(res)
        self.assertIn(f'''The dropnode operation can only be executed at the primary node''', res)

    def tearDown(self):
        self.log.info(f'-----{os.path.basename(__file__)} end-----')